<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); 
	class Tools {

    function _construct()
    {
    }
    
    
	function resize($orgFileName,$targFilePath){
		$CI =& get_instance();
		$CI->load->library('image_lib');
		$config['image_library'] = 'gd2';
	    $config['source_image'] = './uploads/'.$orgFileName;
	    $config['dynamic_output'] = FALSE;
	    $config['quality'] = '100%';
	    $config['new_image'] =$targFilePath;
	    $config['width'] = 600;
	    $config['height'] = 600;
	    $config['create_thumb'] = TRUE;
	    $config['thumb_marker'] = 'm';
	    $config['master_dim'] = 'auto';
	    $CI->image_lib->initialize($config);   
	    if (!$CI->image_lib->resize()){   
	        echo $CI->image_lib->display_errors();   
	    }else{ 
	      $this->deleteFile( $config['source_image']);	  
	      echo "ok";   
	     }
	 }
	 
	 
	 /**
	  * implementation should be instead of checking from cache.
	  * should not check disk path every time.
	  * 
	  * @param unknown_type $path
	  * @return string|string
	  */
	 function checkFolderExist($path){
	 	$CI =& get_instance();		
		$CI->load->helper('file');
	 	if(file_exists($path)){
	 		return true;
	 	}else{
	 		return false;
	 	} 	
	 }
	 
	 
	 function createFolder($path){
	 	mkdir($path,0777,true);	
	 } 
	 
	 function deleteFile($path){
	 	if($this->checkFolderExist($path)){
	 		unlink($path); 
	 	} 	
	 }
	    
    
}

?>